package com.hnit.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hnit.web.bean.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;

@Mapper
@Repository
public interface OrdersMapper extends BaseMapper<Orders> {
    // 这里可以添加自定义的数据库操作方法

    /**
     * 统计总营业额 (只统计已签收和已完成的订单)
     * @return 总营业额
     */
    @Select("SELECT" +
            "  COALESCE(SUM(oi.price * oi.quantity), 0) AS totalRevenue " +
            " FROM " +
            "  orders AS o " +
            "  INNER JOIN order_items AS oi ON o.orderId = oi.orderId " +
            " WHERE " +
            "  o.orderStatus IN (4, 5)")
    BigDecimal getTotalRevenue();
}